<template>
  <div>
    <div>
      <Breadcrumb :breadList="breadList"></Breadcrumb>
    </div>
    <div>
      <el-row :gutter="20">
        <el-col :span="4">
          客户姓名:
          <el-input type="text" size="mini" style="width: 70%"></el-input>
        </el-col>
        <el-col :span="4">
          客户电话:
          <el-input type="text" size="mini" style="width: 70%"></el-input>
        </el-col>
        <el-col :span="4">
          公司名称:
          <el-input type="text" size="mini" style="width: 70%"></el-input>
        </el-col>
      </el-row>
      <div align="left">
        <el-button size="mini" type="primary">搜索</el-button>
        <el-button size="mini">清除</el-button>
      </div>
      <div align="left">
        <el-button size="mini" type="primary" @click="addCustomerVisible=true">新增</el-button>
      </div>
    </div>
    <!--新增机器-->
    <div>
      <el-dialog v-model="addCustomerVisible" title="新增客户" width="30%" center>
        <el-form ref="form" :model="formData" label-width="120px">
          <el-form-item label="客户名称">
            <el-input v-model="formData.name"></el-input>
          </el-form-item>
          <el-form-item label="联系电话">
            <el-input v-model="formData.phone"></el-input>
          </el-form-item>
          <el-form-item label="公司名称">
            <el-input v-model="formData.company"></el-input>
          </el-form-item>
          <el-form-item label="公司地址">
            <el-input v-model="formData.address"></el-input>
          </el-form-item>
        </el-form>
        <template #footer>
          <span class="dialog-footer">
            <el-button type="primary" @click="addCustomer">确认</el-button>
            <el-button @click="addCustomerVisible = false">取消</el-button>
          </span>
        </template>
      </el-dialog>
    </div>
    <div>
      <el-table :data="tableData" height="600" border style="width: 100%">
        <el-table-column prop="index" label="序号" width="80" />
        <el-table-column prop="company" label="客户公司" width="180" />
        <el-table-column prop="address" label="地址" width="300" />
        <el-table-column prop="name" label="客户名称" width="180" />
        <el-table-column prop="phone" label="联系电话" width="180" />
        <el-table-column fixed="right" label="操作" width="120">
          <template #default>
            <el-button type="text" size="small">编辑</el-button>
            <el-button type="text" size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination background layout="prev, pager, next" :total="1000">
      </el-pagination>
    </div>

  </div>
</template>

<script>
import Breadcrumb from "@/components/Breadcrumb";
import httpService from "@/http/httpService";

export default {
  name: 'Customer',
  components: {
    Breadcrumb
  },
  data() {
    return {
      addCustomerVisible: false,
      formData: {
        uuid:'',
        company: '',
        address: '',
        name: '',
        phone: '',
      },
      breadList: [
        'homePage',
        '客户管理'
      ],
      tableData: []
    }
  },
  methods: {
    addCustomer() {
      httpService.post('/api/customer/add', null, this.formData)
          .then(res=>{
            if (res.code === "200") {
              console.log(res)
            }else {
              console.log(res)
            }
            this.addCustomerVisible = false
          }, err => {
            console.log(err)
            this.addCustomerVisible = false
          })
    },
  }
}
</script>
